package Yunzai

import (
	"fmt"
	"io/ioutil"
	"os"
	"bufio"
	"strings"
)

type Admin struct {
	MasterQQ        []int64  `yaml:"masterQQ"`
	DisableGuildMsg bool     `yaml:"disableGuildMsg"`
	DisablePrivate  bool     `yaml:"disablePrivate"`
	DisableMsg      string   `yaml:"disableMsg"`
	DisableAdopt    []string `yaml:"disableAdopt"`
	WhiteGroup      []string `yaml:"whiteGroup"`
	BlackGroup      []string `yaml:"blackGroup"`
	BlackQQ         []string `yaml:"blackQQ"`
}

type Account struct {
	QQ         string `yaml:"qq"`
	Password   string `yaml:"pwd"`
	Login_type string `yaml:"platform"`
}

type DeviceConfig struct {
	Begin       string `json:"--begin--"`
	Product     string `json:"product"`
	Device      string `json:"device"`
	Board       string `json:"board"`
	Brand       string `json:"brand"`
	Model       string `json:"model"`
	WifiSSID    string `json:"wifi_ssid"`
	Bootloader  string `json:"bootloader"`
	AndroidID   string `json:"android_id"`
	BootID      string `json:"boot_id"`
	ProcVersion string `json:"proc_version"`
	MacAddress  string `json:"mac_address"`
	IPAddress   string `json:"ip_address"`
	IMEI        string `json:"imei"`
	Incremental string `json:"incremental"`
	End         string `json:"--end--"`
}

func readFile(path string) ([]byte, error) {
    file, err := os.Open(path)
    if err != nil {
        return nil, fmt.Errorf("打开文件失败：%v", err)
    }
    defer file.Close()

    data, err := ioutil.ReadAll(file)
    if err != nil {
        return nil, fmt.Errorf("读取文件失败：%v", err)
    }

    return data, nil
}

// 写入文件
func writeFile(path, content string) error {
    file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0644)
    if err != nil {
        return fmt.Errorf("打开文件失败：%v", err)
    }
    defer file.Close()

    writer := bufio.NewWriter(file)
    defer writer.Flush()

    _, err = writer.WriteString(content)
    if err != nil {
        return fmt.Errorf("写入文件失败：%v", err)
    }

    return nil
}
//连接符前面加空格
func addSpaceBeforeHyphen(yamlData string) string {
	lines := strings.Split(yamlData, "\n")
	for i, line := range lines {
		if strings.Contains(line, "-") && !strings.HasPrefix(line, " -") {
			lines[i] = strings.Replace(line, "-", "  -", 1)
		}
	}
	return strings.Join(lines, "\n")
}

